using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using slcl;

namespace slcl.TestClient.GUI
{
    public partial class LogDisplay : Form
    {
        public LogDisplay()
        {
            InitializeComponent();
        }


        public void Run()
        {
            Application.Run(this);
        }

        // necessary since only one thread ever updates the GUI.
        // We could in theory let the gui thread handle the queue, but that would not be optimal.
        public delegate void PostLogEntryCallback(string msg, Helpers.LogLevel lvl);
        public void PostLogEntry(string msg, Helpers.LogLevel lvl)
        {
            if (logRichTextBox.InvokeRequired)
            {
                this.Invoke(new PostLogEntryCallback(PostLogEntry), new object[] { msg, lvl });
            }
            else
            {
                bool post = false;
                switch (lvl)
                {
                    case Helpers.LogLevel.Debug:
                        post = logDebugCheckBox.Checked;
                        break;
                    case Helpers.LogLevel.Info:
                        post = logInfoCheckBox.Checked;
                        break;
                    case Helpers.LogLevel.Warning:
                        post = logWarningCheckBox.Checked;
                        break;
                    case Helpers.LogLevel.Error:
                        post = logErrorCheckBox.Checked;
                        break;
                }
                if (post)
                {
                    logRichTextBox.AppendText("\r\n" + lvl.ToString() + " " + DateTime.Now.ToLongTimeString() + " " + msg);
                    logRichTextBox.Update();
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}